"""
Problem 61: https://projecteuler.net/problem=61


"""

# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = VSCODE Python3.8.3
@creat_time = 2022/5/19
'''


def solution(d: int = 4) -> tuple:
    lower,upper = 10**(d-1),10**d
    p3 = [(n, n*(n+1)//2)
          for n in range(150) if lower <= n*(n+1)//2 < upper]
    p4 = [(n, n*n) for n in range(150) if lower <= n*n < upper]
    p5 = [(n, n*(3*n-1)//2)
          for n in range(150) if lower <= n*(3*n-1)//2 < upper]
    p6 = [(n, n*(2*n-1))
          for n in range(150) if lower <= n*(2*n-1) < upper]
    p7 = [(n, n*(5*n-3)//2)
          for n in range(150) if lower <= n*(5*n-3)//2 < upper]
    p8 = [(n, n*(3*n-2))
          for n in range(150) if lower <= n*(3*n-2) < upper]
    
    # print(p3,p4,p5,p6,p7,p8)
    res = []
    for p3n in p3:
        for p4n in p4:
            if p4n[0] == p3n[0] or p4n[1]//100 != p3n[1] % 100:
                continue
            for p5n in p5:
                if p5n[0] == p4n[0] or p5n[1]//100 != p4n[1] % 100:
                    continue
                for p6n in p6:
                    if p6n[0] == p5n[0] or p6n[1]//100 != p5n[1] % 100:
                        continue
                    for p7n in p7:
                        if p7n[0] == p6n[0] or p7n[1]//100 != p6n[1] % 100:
                            continue
                        for p8n in p8:
                            if p8n[0] == p7n[0]:
                                continue
                            if  p8n[1]//100 == p7n[1] % 100:
                                res.append((p3n,p4n,p5n,p6n,p7n,p8n))

    return res


if __name__ == "__main__":
    import doctest
    doctest.testmod(verbose=False)

    print(solution())
    # find 2
    # [((94, 4465), (81, 6561), (64, 6112), (25, 1225), (32, 2512), (21, 1281)), 
    # ((105, 5565), (81, 6561), (64, 6112), (25, 1225), (32, 2512), (21, 1281))]
